<?php 
require_once 'config.inc.php';

$page = $_GET['page'];
$sub_menu = $_GET['sub_menu'];
$style = $_GET['style'];
//分页
$pager = $_GET['pager'];
if(empty($style)){
	$style = 'blue';	
}

/* 调用后台模板 */
$tpl = new Template('admin');
if($sub_menu == 'menu_list'){
	$cat = new Category(UNIT_MENU);
}else{
	$cat = new Category(UNIT_CMS);
}
/* 安全过滤 */
$safe = new Safe();

//页码
$pagination = new Pagination($pager,'260','30');

$list = $cat->selectCat('');
$p_list = $cat->selectParentCat();

if($_SERVER[REQUEST_METHOD] == 'POST' && !empty($_POST)){
	/* 转换表单数据 */
	$safe_post = $safe->convertForm($_POST);
	//debug($safe_post);
	$cat->addCat($safe_post);
	
}elseif($_GET['action'] == "delete" && is_numeric($_GET['id'])){
	if($cat->deleteCat($_GET['id'])){
		$msg_state = 'success';
		$msg = "删除成功";
	}else{
		$msg_state = 'error';
		$msg = "删除失败";
	}
}
	
$tpl->assign('style',$style);
$tpl->assign('list',$list);
$tpl->assign('p_list',$p_list);
$tpl->assign('pagination',$pagination);

$tpl->assign('msg_state',$msg_state);
$tpl->assign('msg',$msg);

$tpl->subMenu($sub_menu,'','category');
$tpl->page($page,'category');
?>